package com.jiuli.liping.controller;

import com.jiuli.liping.vo.Classification;
import com.jiuli.liping.vo.Favorites;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiuli.liping.service.FavoritesService;

import java.util.List;

/**
 * Author zyl
 * Date  2020-06-08
 */
@RestController
@RequestMapping(value = "/favorites")
public class FavoritesController {
    @Autowired
    private FavoritesService favoritesService;

    @RequestMapping(value = {"/list", ""}, method = RequestMethod.GET)
    public Object list() {
        List<Favorites> favoritess = favoritesService.findAllList();
        return favoritess;
    }

    @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
    public Object get(@RequestParam String id) {
        Favorites favorites = favoritesService.get(id);
        return favorites;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public String insert(@RequestBody Favorites favorites) {
        if (favoritesService.insert(favorites) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<Favorites> favoritess) {
        if (favoritesService.insertBatch(favoritess) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody Favorites favorites) {
        if (favoritesService.update(favorites) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody Favorites favorites) {
        if (favoritesService.delete(favorites) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    /**
     * 查询收藏夹商品
     */
    @RequestMapping(value = {"/getFavorites"}, method = RequestMethod.POST)
    public List<Classification> getFavorites(@RequestBody String userNum) {
        List<Classification> list = favoritesService.getFavorites(userNum);
        return list;
    }
}
